<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<style type="text/css">
		/* 设置打印布局（横向、纵向、边距） */
		 @media print {
		    @page {
		      /* 纵向 */
		      size: portrait; 
		      /* 横向 */
		      size: landscape;
		      /* 边距 上右下左 */
		      margin: 1cm 2cm 1cm 2cm;
		    }
			/* 去除浏览器默认页眉页脚 */
			@page {
			    margin: 0;
			  }
			  body {
			    margin: 1cm;
			  }

		}
		
	</style>
	<body>
		/*设置默认横向打印*/
		@page {
		   size: landscape;
		}
		/*设置默认纵向打印*/
		@page {
		   size: portrait;
		}
		<!-- https://blog.csdn.net/qq_38128179/article/details/103344021 -->
		<script type="text/javascript">
			var cssPagedMedia = (function () {
				var style = document.createElement('style');
				document.head.appendChild(style);
				return function (rule) {
					style.innerHTML = rule;
				};
			}());
			cssPagedMedia.size = function (size) {
				cssPagedMedia('@page {size: ' + size + '}');
			};
			let mode = 1
			if (mode === 2) {
				console.log('landscape')
				cssPagedMedia.size('landscape');
			} else {
				console.log('portrait')
				cssPagedMedia.size('portrait');
			}
			
		</script>
	</body>
</html>
